package error.processing;

import word.parser.WordElement;

import java.util.TreeSet;

public class MyErrorProcessing implements Comparable {
    private static final TreeSet<MyErrorProcessing> errors = new TreeSet<>();
    private static boolean haveReturn = false;
    protected final WordElement errorElement;
    protected final ErrorType errorType;

    private MyErrorProcessing(ErrorType type, WordElement element) {
        this.errorElement = element;
        this.errorType = type;
        errors.add(this);
    }

    public static TreeSet<MyErrorProcessing> getErrors() {
        return errors;
    }

    public static boolean isHaveReturn() {
        return haveReturn;
    }

    public static void haveReturn() {
        MyErrorProcessing.haveReturn = true;
    }

    public static void withoutReturn() {
        MyErrorProcessing.haveReturn = false;
    }

    public static MyErrorProcessing buildErrorProcessing(
            ErrorType type, WordElement element) {
        return new MyErrorProcessing(type, element);
    }

    @Override
    public int compareTo(Object o) {
        assert o.getClass().equals(this.getClass());
        MyErrorProcessing errorProcessing = (MyErrorProcessing) o;
        return this.errorElement.getLineNum() > errorProcessing.errorElement.getLineNum() ? 1 : -1;
    }

    @Override
    public String toString() {
        return errorElement.getLineNum() + " " + errorType;
    }

    public enum ErrorType {
        a,
        b,
        c,
        d,
        e,
        f,
        g,
        h,
        i,
        j,
        k,
        l,
        m
    }
}
